<template>
  <div class="home">
    <el-container>
      <el-header>
        <h1>后台管理</h1>
        <el-button type="info" @click="out">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isCollapse ? '60px' : '200px'">
          <i @click="put" class="isCollapse">|||</i>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :collapse="isCollapse"
            router
          >
            <el-submenu
              :index="item1.id"
              v-for="item1 in menus"
              :key="item1.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ item1.authName }}</span>
              </template>

              <el-menu-item-group
                v-for="item2 in item1.children"
                :key="item2.id"
              >
                <el-menu-item :index="item2.path">{{
                  item2.authName
                }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { getMenusApi } from "../utils.js/api";
export default {
  data() {
    return {
      isCollapse: false,
      menus: [],
    };
  },
  created() {
    this.getMenus();
  },
  methods: {
    async getMenus() {
      const res = await getMenusApi();
      console.log(res);
      this.menus = res;
    },
    put() {
      this.isCollapse = !this.isCollapse;
    },
    out() {
      sessionStorage.removeItem("token")
      this.$router.push("/login");
    },
  },
};
</script>

<style>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  height: 100vh;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>
